﻿using DCIMAP.GANS.GeneticAlgorithms.Kit;
using DCIMAP.GANS.GeneticAlgorithms.Legacy;
using GAIQ;
using System;
using System.Collections.Generic;
using System.Text;


[System.Serializable]
public class IQMutator : ArrayMutator
{
    static Random _r = new Random();

    public override object Mutate(ArrayGene gene1, int position)
    {
          TreeGene gene = (TreeGene)gene1;
          string sumbol = gene.NodeCode[position];
          object s_r;
          int n;
          if (ListOp.isOp(sumbol))
          {
              n = _r.Next(ListOp.getLength());
              while (ListOp.getSymbols()[n] == sumbol) { n = _r.Next(ListOp.getLength()); }
              s_r = ListOp.getSymbols()[n];
          }
          else
          {
              switch (sumbol)
              {
                  case "x": n = _r.Next(2);
                      if (n == 0) { s_r = "1"; }
                      else { s_r = "y"; }
                      break;
                  case "y": n = _r.Next(2);
                      if (n == 0) { s_r = "1"; }
                      else { s_r = "x"; }
                      break;
                  default: n = _r.Next(3);
                      switch (n)
                      { 
                          case 0:
                              s_r = "x";
                              break;
                          case 1:
                              s_r = "y";
                              break;
                          default:
                              s_r = Convert.ToString(_r.Next(Math.Max(Convert.ToInt32(sumbol)-10,0),Convert.ToInt32(sumbol)+10));
                              break;
                      }
                      break;
              }
          }
        return s_r;

    }
}